﻿Public Class Agenda_CTRL
    Implements IDisposable

    Private _EDM As AniFormEntities
    Private _listeVeto As List(Of Veterinaires)
    Private _indexCourant As Integer
    Private _agendaCourant As Agendas

#Region "Cycle de vie du controleur Agenda"

    Public Sub New(ByVal edm As AniFormEntities)
        _EDM = edm
        _listeVeto = New List(Of Veterinaires)
        Dim requete As IEnumerable(Of Veterinaires) = (From unVeto In _EDM.Veterinaires Select unVeto Where unVeto.Archive = False)
        _listeVeto.AddRange(requete)
        _agendaCourant = New Agendas
    End Sub

    Private disposedValue As Boolean = False        ' Pour détecter les appels redondants

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
            End If
            _EDM.Dispose()
            For Each element In _listeVeto
                element = Nothing
            Next
            For Each element In _listeVeto
                element = Nothing
            Next
            _EDM.Dispose()
            _listeVeto.Clear()
            _listeVeto = Nothing
            _agendaCourant = Nothing
        End If
        Me.disposedValue = True
    End Sub


    Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

#End Region

    Public Property indexCourant() As Integer
        Get
            Return _indexCourant
        End Get
        Set(ByVal value As Integer)
            _indexCourant = value
        End Set
    End Property

    Public Property agendaCourant() As Agendas
        Get
            Return _agendaCourant
        End Get
        Set(ByVal value As Agendas)
            _agendaCourant = value
        End Set
    End Property



    Public Function getAgendaJour(ByVal veto As Veterinaires, ByVal jour As Date)
        Dim jourplus1 As Date = DateAdd(DateInterval.Day, 1, jour)
        Dim requete As IEnumerable(Of Agendas) = (From unAgenda In _EDM.Agendas _
                                                  Select unAgenda _
                                                  Where unAgenda.DateRdv > jour.Date _
                                                  And unAgenda.DateRdv < jourplus1.Date _
                                                  And unAgenda.CodeVeto = veto.CodeVeto _
                                                  Order By unAgenda.DateRdv)
        Return requete.ToList
    End Function

    Public ReadOnly Property getListeVeto() As List(Of Veterinaires)
        Get
            Return _listeVeto
        End Get
    End Property

End Class
